<template>
	<view>
		用户名
		<input type="text" v-model:value="userName" />
		密码
		<input type="password" v-model="password">

		<button type="default" @click="login">登录</button>
	</view>
</template>

<script>
	import {login} from "../../api/user-api.js"
	export default {
		data() {
			return {
				userName: "",
				password: ""
			}
		},
		methods: {
			login() {
				if (this.userName && this.password) {
					login(this.userName,this.password).then(res=>{
						if(res.data.code == 0){
							// 登录成功
							this.$store.commit("changeLoginStatus",{isLogin:true,userInfo:res.data.userInfo})
							uni.navigateBack()
						}else{
							uni.showModal({
								title:"登录失败",
								content:res.data.msg
							})
						}
					})
				} else {
					uni.showToast({
						title: "请填写完整信息"
					})
				}
			}
		}
	}
</script>

<style>

</style>
